#!/usr/bin/sh
modprobe kathrein_micom paramDebug=0

if [ -e /var/etc/.firstboot ]; then
   #fp_control does not work here
   echo "WAIT 1 min" >/dev/vfd
   echo "WAIT 1 min"
   rm /var/etc/.firstboot
   touch /dev/.devfsd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi

if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

modprobe e2_proc

if [ -e /etc/init.d/autofs ]; then
   /etc/init.d/autofs start
fi

if [ ! -e /var/etc/.firstboot ]; then

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   NFS=`grep -c nfs /proc/cmdline`
   if [ "$NFS" -eq "1" ]; then
      # We can not correct the mac from userspace if we are booting from nfsroot
      echo "Booting from nfs, don't set network"
   else
      HWADDR=`strings /dev/mtdblock2 | tail -n 1`
      ifconfig eth0 down
      ifconfig eth0 hw ether ${HWADDR}
      ifconfig eth0 up
   fi

   fp_control -c

   #green led on
   fp_control -l 2 1
   #led brightness
   fp_control -led 80

   echo "init stmfb"
   modprobe stmcore-display-sti7105
   modprobe stmfb display0=1280x720-32@50:15m:pal:yuv:yuv;# display1=720x576-16@50:1m:pal:cvbs;

   echo "LOADING MODULES"   
   fp_control -t "LOADING MODULES"

   echo "load a firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf
   echo "load v firmware"
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xfe211000:136:set2 mailbox1=0xfe212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:512:0x40000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init AVS"
   modprobe avs type=stv6417

   player=`cat /proc/stb/player/version`
   if [ $player=='player191' ]; then
      echo "init player 191"
   elif [ $player=='player179' ]; then
      echo "init player 179"
   else
      echo "init player 131"
   fi
   modprobe mmelog
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   modprobe pseudocard

   modprobe frontend_platform
   modprobe socket
   modprobe lnbh221
   modprobe lnb_pio
   modprobe lnb_a8293
   modprobe avl6222
   modprobe ufs913_cic
   if [ $player=='player191' ]; then
      # Full feature pti
      modprobe pti waitMS=20 videoMem=4096
      if [ $?=='2' ]; then
         # Simple pti
         modprobe pti
      fi
      modprobe stm_monitor
      modprobe stmsysfs
      modprobe stmdvb
   elif [ $player=='player179' ]; then
      # Full feature pti
      modprobe pti waitMS=20 videoMem=4096
      if [ $?=='2' ]; then
         # Simple pti
         modprobe pti
      fi
      modprobe stm_monitor
      modprobe stmsysfs
      modprobe stmdvb
   else
      modprobe pti
      modprobe stmdvb
      modprobe stm_monitor
   fi
   modprobe player2
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe silencegen

   modprobe bpamem

   showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   echo "init frontpanel"
   modprobe simu_button

   #params:
   #period
   #delay
   /usr/bin/evremote2 10 120 &

   # timefix e2
   # date -s "121220001970"

if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   /etc/init.d/network start &

   echo "LOADING e2" > /dev/vfd
   echo "LOADING e2"

   stfbcontrol a 255

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
      	   init 6;;
		1) echo "1"
		   echo "SHUTDOWN"
		   init 0;;
		2) echo "2"
		   echo "REBOOT"
		   init 6;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
           init 6;;
      esac
   done 
fi
